﻿Imports System.Data.OleDb

Public Class Robot_Add
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

   

    Protected Sub but_Submit_Click(sender As Object, e As EventArgs) Handles but_Submit.Click
       

        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"

        Dim fileLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & newFileName
        ' adding picture if not present
        If F_Picture.HasFile Then
            F_Picture.SaveAs(fileLocationOnServerHardDisk)
        End If

        'Database
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("roboticsConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into mastTable1(Robot_Name,Ranking,Creator,Picture,Wins,Losses,Robot_Description,Weapons,DateTimeAdded) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_RobotName.Text)
        cmd.Parameters.AddWithValue("@f2", 1)
        cmd.Parameters.AddWithValue("@f3", "barrance")
        cmd.Parameters.AddWithValue("@f4", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f5", 1)
        cmd.Parameters.AddWithValue("@f6", 1)
        cmd.Parameters.AddWithValue("@f7", tb_Desc.Text)
        cmd.Parameters.AddWithValue("@f8", tb_Weapons.Text)
        cmd.Parameters.AddWithValue("@f9", Date.Today)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirm.aspx")
    End Sub

    Protected Sub tb_RobotName_TextChanged(sender As Object, e As EventArgs) Handles tb_RobotName.TextChanged

    End Sub
End Class